<?php	
	// Search and modify illegal portions
	$_POST = str_replace("'","''",$_POST);
	$_POST = str_replace("\\","\\\\",$_POST);
	
	// Set birthday up for storing in database
	$birthday = date('Y-m-d',strtotime($_POST['birthMon']."/".$_POST['birthDay']."/".$_POST['birthYear']));
	
	// Check for blank entries that are essential and fix when necessary
	// Check mail
	if(strlen($_POST['email']) == 0)
		$_POST['email'] = $data['email'];
	
	// Check username
	if(strlen($_POST['usr']) == 0)
		$_POST['usr'] = $data['username'];
		
	// Check password
	if(strlen($_POST['pwd']) == 0)
		$_POST['pwd'] = $data['password'];
		
    // Search for unmodifable errors
	$clean = true;
	$error = "<div align=\"center\">";
	$error = $error . "The information you submitted have the following errors:<br/><div style='color:#F00'>";
	
	// Check email for errors
	$email = $_POST['email'];
	$atIndex = strpos($email,"@");
	if($atIndex === false){
		$error = $error . "There is no @ sign in your email.<br/>";
		$clean = false;
	}
	$atIndex2 = strpos($email,"@",$atIndex+1);
	if(!($atIndex2 === false) && $clean){
		$error = $error . "There are multiple @ signs in your email.<br/>";
		$clean = false;
	}
	$dotIndex = strpos($email,".");
	if($dotIndex === false && $clean){
		$error = $error . "There is no . (dot) sign in your email.<br/>";
		$clean = false;
	}
	$dotIndex2 = strpos($email,".",$dotIndex+1);
	if(!($dotIndex2 === false) && $clean){
		$error = $error . "There are multiple . (dot) signs in your email.<br/>";
		$clean = false;
	}
	if($atIndex > $dotIndex && $clean){
		$error = $error . "The . (dot) sign precedes the @ sign in your email.<br/>";
		$clean = false;
	}
	if($atIndex == 0 && $clean){
		$error = $error . "The @ sign is not preceded by anything your email.<br/>";
		$clean = false;
	}
	if($atIndex == $dotIndex - 1 && $clean){
		$error = $error . "The @ sign immediately precedes the . (dot) sign in your email.<br/>";
		$clean = false;
	}
	if($dotIndex == strlen($email) - 1 && $clean){
		$error = $error . "The . sign is at the end your email.<br/>";
		$clean = false;
	}
	
	// Check Number for errors
	$contact = $_POST['num'];
	if(!ctype_digit($contact)){
		$error = $error . "The contact number you entered has non-numeric characters.<br/>";
		$clean = false;
	}
	$error = $error . "</div>Please check the information you have submitted.<br/>";
?>